#include "Torus.hh"
#include "Bug.h"
#include <iostream>
#include <iomanip>
#include <cassert>

Bug bug("test");
#ifdef DEBUG
int DEBUGTracker::depth = 1;
#endif



int main(void)
{

  const unsigned X = 4;
  const unsigned Y = 9;

  Torus toto;

  toto.init(X,Y);
  
  for(unsigned i=0; i!=X; ++i)
    {
      for(unsigned j=0; j!=Y; ++j)
        bug << ' ' << std::setw(2) << toto.to_uLocation(i,j);
      bug << std::endl;
    }
  bug << std::endl;


  bug << "direction map" << std::endl;
  for(unsigned i=0; i!=X; ++i)
    {
      for(unsigned j=0; j!=Y; ++j)
        bug << ' ' << toto.to_str(toto.to_uLocation(i,j));
      bug << std::endl;
    }
  bug << std::endl;
  
  for(unsigned d=0; d!=Torus::ALLDIRECTIONS; ++d)
    {
      bug << "Direction: " << toto.direction_name(d) << std::endl;
      for(unsigned i=0; i!=X; ++i)
	{
	  for(unsigned j=0; j!=Y; ++j)
	    bug << ' ' << std::setw(2) 
                << toto.to_str(toto.to_uLocation(i,j)) << "->" << toto.to_str(toto.getLocation(toto.to_uLocation(i,j),d));
	  bug << std::endl;
	}
      bug << std::endl;
    }

  for(unsigned r=0; r!=X; ++r)
    {
      for(unsigned c=0; c!=Y; ++c)
         {
             assert(toto.getLocation(toto.to_uLocation(r,c), 0) == toto.to_uLocation((r-1+X)%X,c));
             assert(toto.getLocation(toto.to_uLocation(r,c), 1) == toto.to_uLocation(r,(c+1)%Y));
             assert(toto.getLocation(toto.to_uLocation(r,c), 2) == toto.to_uLocation((r+1)%X,c));
             assert(toto.getLocation(toto.to_uLocation(r,c), 3) == toto.to_uLocation(r,(c-1+Y)%Y));
             assert(toto.getLocation(toto.to_uLocation(r,c), 4) == toto.to_uLocation(r,c));
         }
    }


  return 0;
}
